package com.hundsun.yr.universal.p2p.bean;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.NumberFormat;

import com.hundsun.yr.universal.library.utils.HsDateUtils;
import com.hundsun.yr.universal.library.utils.HsStringUtils;





/**
 * @Title: InvestRecord.java 
 * @Description: 投资记录
 * @date 2016-1-22 下午5:44:24 
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com 
 * @replace author:
 * @replace date:
 * @version V1.0   
 */
public class InvestRecord extends ResponseBean implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	/**
	 * 取值的key
	 */
	public static String BASEKEY="investRecord";
	/**
	 * 投资金额
	 */
	private BigDecimal amount;
	/**
	 * 投资单号
	 */
	private String investVchrNo;
	/**
	 * 投资人编号
	 */
	private String userNo;
	/**
	 * 付款时间 
	 */
	private String payTime;
	/**
	 * 投资人姓名
	 */
	private String userName;
	/**
	 * 投资人电话
	 */
	private String mobile;
	public BigDecimal getAmount() {
		return amount;
	}
	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}
	public String getInvestVchrNo() {
		return investVchrNo;
	}
	public void setInvestVchrNo(String investVchrNo) {
		this.investVchrNo = investVchrNo;
	}
	public String getUserNo() {
		return userNo;
	}
	public void setUserNo(String userNo) {
		this.userNo = userNo;
	}
	public String getPayTime() {
		return payTime;
	}
	public void setPayTime(String payTime) {
		this.payTime = payTime;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getMobile() {
		
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
	/**
	 * 要显示投资人电话
	 * @return
	 */
	public String displayMobile(){
		String mMobile=HsStringUtils.abbreviate(mobile, "*****", 3, 8);
		return mMobile;
	}
	
	/**
	 * 要显示投资人电话
	 * @return
	 */
	public String displayUserName(){
		String username=HsStringUtils.abbreviate(userName, "**", 0, userName.length()-1);
		return username;
	}

	/**
	 * 要显示的付款时间 
	 * @return
	 */
	public String displayPayTime(){
		String mPayTime=HsDateUtils.timeformat(HsDateUtils.farmat_date_1, payTime);
		return mPayTime;
	}
	
	
	/**
	 * 要显示投资人电话
	 * @return
	 */
	public String displayMoney(){
		String money=roundingAmount(amount, false, 10000);
		return money;
	}
	
	
	/**
	 * 
	 * @param money 
	 * @param flag true四舍五入（false截位）
	 * @return
	 */
	private String roundingAmount(BigDecimal money,boolean flag,int wanUnit){
		NumberFormat nt = NumberFormat.getInstance();
		nt.setMaximumFractionDigits(1);
		String unit = "元";
//		BigDecimal yi = new BigDecimal(100000000);
		BigDecimal wan = new BigDecimal(10000);
//		if (money.compareTo(yi) != -1) {//money>100000000
//			money = money.divide(yi);
//			unit = "亿";
//		} else 
		
//		if (money.compareTo(new BigDecimal(wanUnit)) != -1) {
//			money = money.divide(wan);
//			unit = "万";
//		} 
		if(money.compareTo(new BigDecimal(wanUnit))>=0){
			money = money.divide(wan);
			unit = "万";
		}
		if(flag){
			money = money.setScale(1, BigDecimal.ROUND_HALF_UP);
		}else{
			money = money.setScale(1, BigDecimal.ROUND_DOWN);
		}
		if(money.divideAndRemainder (new BigDecimal(1))[1].doubleValue()>0){
			nt.setMinimumFractionDigits(1);
		}
//		String res = setMaxDigits(MathUtils.string2double(money.toString()), 2);
		return nt.format(money.doubleValue())+unit;
	}
	
}
